//
//  NetworkBaseUrl.m
//  jinwan
//
//  Created by 王尧 on 2017/5/26.
//  Copyright © 2017年 wy. All rights reserved.
//

#import "NetworkBaseUrl.h"

/** API */
static NSString *const host_url_dis = @"https://api.bx.jinyishe.cn/";
static NSString *const host_url_dev = @"http://api.bx.jinyishe.cn/";
static NSString *const host_url_local = @"";

/** login */
static NSString *const login_url_dis = @"https://reg.jinyishe.cn/";
static NSString *const login_url_dev = @"http://reg2.jinyishe.cn/";
static NSString *const login_url_local = @"";

/** Image */
static NSString *const image_url_dis = @"https://api.jinyishe.cn/";
static NSString *const image_url_dev = @"http://api2.jinyishe.cn/";
static NSString *const image_url_local = @"";




@implementation NetworkBaseUrl

NSString* availableImageUrl(NSString *path)
{
    if (path.length > 0) {
        path = [[NetworkBaseUrl net_ImageBaseUrl] stringByAppendingString:path];
    } else {
        path = nil;
    }
    return path;
}


NSString* availableAPIUrl(NSString *path)
{
    NSString * str = [[NetworkBaseUrl net_UrlHost] stringByAppendingString:path];
    return str;
}


+ (Net_ENV)env
{
    return [[ServiceConfig shareInstance] env];
}

+ (NSString *)net_UrlHost
{
    NSDictionary *info = [self hostDescriptionInfoOfEnv:[self env]];
    if (info) {
        return info[@"url"];
    } else {
        return @"url-error-please check ENV";
    }
}


+ (NSString *)net_ImageBaseUrl
{
    switch ([self env]) {
        case Net_ENV_DEV:
        {
            return image_url_dev;
            break;
        }
        case Net_ENV_DIS:
        {
            return image_url_dis;
            break;
        }
        case Net_ENV_LOCAL:
        {
            return image_url_local;
            break;
        }
        default:
            return @"";
            break;
    }
    
}


+(NSString *)net_loginBaseUrl
{
    NSDictionary *info = [self loginDescriptionInfoOfEnv:[self env]];
    if (info) {
        return info[@"url"];
    } else {
        return @"url-error-please check ENV";
    }
}


#pragma mark - 获取环境Description

+ (NSDictionary *)hostDescriptionInfoOfEnv:(Net_ENV)env
{
    switch (env) {
        case Net_ENV_DEV:
        {
            return @{@"env":@(Net_ENV_DEV),
                     @"url":host_url_dev,
                     @"description":@"Net_ENV_DEV"};
            break;
        }
        case Net_ENV_DIS:
        {
            return @{@"env":@(Net_ENV_DIS),
                     @"url":host_url_dis,
                     @"description":@"Net_ENV_DIS"};
            break;
        }
        case Net_ENV_LOCAL:
        {
            return @{@"env":@(Net_ENV_LOCAL),
                     @"url":host_url_local,
                     @"description":@"Net_ENV_LOCAL"};
            break;
        }
            
        case Net_ENV_CUSTOM:
        {
            NSDictionary *customDic = [ServiceConfig shareInstance].customHost;
            NSString *dev_custom_host = @"";
            if (customDic) {
                dev_custom_host = customDic[@"API"];
            }
            return @{@"env":@(Net_ENV_CUSTOM),
                     @"url":dev_custom_host,
                     @"description":@"Net_ENV_CUSTOM"};
            break;
        }
        default:
            return nil;
            break;
    }
}

+ (NSDictionary *)loginDescriptionInfoOfEnv:(Net_ENV)env
{
    switch (env) {
        case Net_ENV_DEV:
        {
            return @{@"env":@(Net_ENV_DEV),
                     @"url":login_url_dev,
                     @"description":@"Net_ENV_DEV"};
            break;
        }
        case Net_ENV_DIS:
        {
            return @{@"env":@(Net_ENV_DIS),
                     @"url":login_url_dis,
                     @"description":@"Net_ENV_DIS"};
            break;
        }
        case Net_ENV_LOCAL:
        {
            return @{@"env":@(Net_ENV_LOCAL),
                     @"url":login_url_local,
                     @"description":@"Net_ENV_LOCAL"};
            break;
        }
            
        case Net_ENV_CUSTOM:
        {
            NSDictionary *customDic = [ServiceConfig shareInstance].customHost;
            NSString *dev_custom_host = @"";
            if (customDic) {
                dev_custom_host = customDic[@"login"];
            }
            return @{@"env":@(Net_ENV_CUSTOM),
                     @"url":dev_custom_host,
                     @"description":@"Net_ENV_CUSTOM"};
            break;
        }
        default:
            return nil;
            break;
    }
}

@end
